-- NewguildChallengePanel

local NewguildChallengeRender = import( ".renders.NewguildChallengeRender" )

local ClassRef = app.mvc.createPanelClass(...)

local challengeNum = 5 -- 挑战个数

function ClassRef.create(node)
	local sprite = ClassRef.extend(node)
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._challengeNodeList = {}
	for i = 1, challengeNum do
		local challengeTemp = NewguildChallengeRender.create( self._ui.Panel_mid:getChildByName( "node_" .. i ) )
		challengeTemp:onBtnClick( function( op, ... )
			executeFunc(self._onOperate, op, ...)
		end )
		self._challengeNodeList[ i ] = challengeTemp
	end
end

-- dataTemp = { challengeVo, challengeVo,, }
function ClassRef:refreshContent( dataTemp )
	local hadCompletedTimes = 0
	for i,v in ipairs( dataTemp ) do
		if v:isCompleted() then
			hadCompletedTimes = hadCompletedTimes + 1
		end
	end
	self._ui.title:setString( string.format( L("guild_challenge_finished"), hadCompletedTimes, challengeNum ) )

	for i = 1, challengeNum do
		self._challengeNodeList[ i ]:setData( { dataTemp, i } )
	end
end

function ClassRef:onOperate( cb )
	self._onOperate = cb
end

return ClassRef
